   function [pdf,logpdf]=pdf_normtr(x,mu,sd,lim); 
%function [pdf,logpdf]=pdf_normtr(x,mu,sd,lim);
%
%Computes pdf and log pdf of 
%         a univariate truncated normal x~N(mu,sigma) 
%   lim=[a,b]  s.t.   a <= x <= b
%   sd is the standard deviation 
%  Use normtrpdf for the variance 
% 
% Alejandro Justiniano 5/25/04 
% ajustiniano@imf.org 
a=lim(1); 
b=lim(2); 
if b <= a; 
    error(' Invalid entry a/b in pdfnormt'); 
end; 
deno=normcdf(b,mu,sd)-normcdf(a,mu,sd); 
num=normpdf(x,mu,sd); 
pdf=num/deno; 
logpdf=log(pdf); 